package view.menus;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import controller.CustomEvent;
import controller.RightClickMenuEventHandler;/** * A class to encapsulate the right click menu for the background of the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
@SuppressWarnings("serial")
public class RightClickBGMenu extends JPopupMenu
{
	private JMenuItem backgroundColour;
	private JMenuItem addBox;	private JMenuItem addLabel;
	private RightClickMenuEventHandler eventHandler;
	private Point point;
	public RightClickBGMenu()
	{
		backgroundColour = new JMenuItem("Background Colour");
		addBox = new JMenuItem("Add Box");		addLabel = new JMenuItem("Add Label");
		point = new Point();
		
		buildMenu();
		eventHandler = new RightClickMenuEventHandler();
		backgroundColour.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("backgroundColour");
				RightClickBGMenu.this.eventHandler.createEvent(event);
			}
		});
		addBox.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("AddBox", e, point);
				RightClickBGMenu.this.eventHandler.createEvent(event);
			}
		});				addLabel.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent e) {				CustomEvent event = new CustomEvent("AddLabel", e, point);				RightClickBGMenu.this.eventHandler.createEvent(event);			}					});		
	}	/**	 * Sets the coordinates of the menu	 * @param x the x coordinate of the menu	 * @param y the y coordinate of the menu	 */
	public void setCoordinates(int x, int y){
		point.setLocation(x, y);
	}	/**	 * Adds the components to the menu	 */
	private void buildMenu(){
		this.add(addBox);		this.add(addLabel);
		this.add(backgroundColour);
	}
}